package com.lgCore.monitor;/**
 * Created by by on 2020/11/7 13:22
 */

import com.lgCore.consumer.model.ClientZkData;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.ChildData;
import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.framework.recipes.cache.TreeCacheListener;

import java.io.UnsupportedEncodingException;

/**
 * 节点监听
 *
 * @program: sxreader_rpc
 * @author: ligang
 * @create: 2020-11-07 13:22
 */
public class TreeCacheMonitor {
    public void monitor(CuratorFramework client, String nadePath) throws Exception {
        TreeCache cache = new TreeCache(client, nadePath);
        TreeCacheListener listener = (client1, event) -> {
            System.out.println("事件类型1：" + event.getType() +
                    " | 路径：" + (null != event.getData() ? event.getData().getPath() : null));
        };
        cache.getListenable().addListener(listener);
        cache.start();
    }

    public void close(TreeCache cache) throws Exception {
        cache.close();
    }

}
